package com.mofeng.myshop.domain.vo;

import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

import com.mofeng.myshop.domain.po.Carmine;
import com.mofeng.myshop.domain.po.UserBase;
import com.mofeng.myshop.domain.vo.base.BaseVo;
import com.mofeng.myshop.domain.vo.user.UserVo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import lombok.experimental.SuperBuilder;

/**
 * @author 作者
 * @since 2024-11-10
 */
@Schema(name = "Carmine Vo", description = "卡密")
@Data
@NoArgsConstructor
@AllArgsConstructor
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class CarmineVo extends BaseVo {
    @Schema(description = "金额")
    private String money;

    @Schema(description = "卡密")
    private String uuid;

    @Schema(description = "是否使用  0没使用 1使用")
    private Integer used;

    private String userName;

    private UserVo user;

    /**
     * Carmine实体 转换为 CarmineVo
     */
    public CarmineVo(Carmine carmine) {
        super(carmine);
        this.money = carmine.getMoney();
        this.uuid = carmine.getUuid();
        this.used = carmine.getUsed();
        UserBase userBase = carmine.getUser();
        if (userBase != null) {
            this.user = new UserVo(userBase);
            this.userName = this.user.getName();
        }
    }

    public static List<CarmineVo> change(Collection<Carmine> carmineCollection) {
        if (carmineCollection == null) {
            return null;
        }
        return carmineCollection.stream().map(CarmineVo::new).collect(Collectors.toList());
    }


}